from pycuda.curandom import rand as curand    # import CUDA random number module

a_gpu = curand((50,))                         # create a 1-d array with random number
b_gpu = curand((50,))                         

from pycuda.elementwise import ElementwiseKernel  # import ElementwiseKernel module

# specify the detail of element-wise operation
lin_comb = ElementwiseKernel(   
    " float a, float *x, float b, float *y, float *z",
    "z[i] = a*x[i] + b*y[i]")

c_gpu = gpuarray.empty_like(a_gpu)            # create a GPU array of same size
lin_comb(5, a_gpu, 6, b_gpu, c_gpu)           # run the ElementwiseKernel function
assert  la.norm((c_gpu -  (5*a_gpu+6*b_gpu)).get()) < 1e-5

print a_gpu
print b_gpu
print c_gpu
